<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- STYLESHEETS -->
    <!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
    <link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
    <link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
    <link rel="stylesheet" type="text/css" href="../../css/responsive.css">
    <link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- SELECT2 -->
    <link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
    <!-- UNIFORM -->
    <link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
    <!-- datatable -->
    <link rel="stylesheet" href="../../js/datatables/datatable.css">
    <link rel="stylesheet" href="../../js/datepicker/datepicker.css">
    <style>
        .data-sta-top .data-sta-btn {
			float: left;
			margin-right: 10px;
		}

		.data-sta .active {
			background-color: transparent;
			color: #000;
		}

		.data-sta .data-sta-money {
			line-height: 30px;
			padding: 10px 0;
		}

		.data-sta .data-sta-money em {
			font-style: normal;
			font-size: 18px;
			margin-left: 5px;
			color: #f60;
		}

		.data-sta .data-sta-money span {
			min-width: 100px;
			margin-right: 60px;
			display: inline-block;
		}
        .dataTables_scrollHeadInner {
            width: auto !important;
        }
        .dataTables_scrollHeadInner table {
            width:  100% !important;
        }
		.index-term {
			line-height: 34px;
		}

		.index-term .radio-inline input {
			margin-top: 9px;
		}
        .dataTables_scrollBody table td,
        .dataTables_scrollHeadInner table th{
            text-align: center;
        }
        .dataTables_scrollBody table tr td:last-child {
            text-align: left;
        }
	</style>
</head>

<body>
    <header class="navbar clearfix" id="header"> </header>

    <!-- PAGE -->
    <section id="page">
        <!-- SIDEBAR -->
        <div id="sidebar" class="sidebar">
            <div class="sidebar-menu nav-collapse">

                <!-- SIDEBAR MENU -->
                <ul>
                </ul>
            </div>


        </div>
        <!-- /SIDEBAR -->
        <div id="main-content">
            <div class="modal fade" id="start-model" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
                aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title">设置生效日期</h4>
                        </div>
                        <div class="modal-body">
                            <div class="form-group" id="form_Order">
                                <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>生效日期：</label>
                                <div class="col-md-4">
                                        <input class="form-control" style="height:34px" type="text" id="startDate" name="startDate"
                                        onfocus="WdatePicker({maxDate:'#F{\'2030-10-01\'}',dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false,readOnly:true})">
                                    <!-- <input type="text" id="startDate" name="startDate" class="form-control bootstrap-datepicker" readonly> -->
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-success start-save">保存</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="container">
                <div class="row">
                    <div id="content" class="col-lg-12">
                        <!-- PAGE HEADER-->
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="page-header">
                                    <!-- STYLER -->

                                    <!-- /STYLER -->
                                    <!-- BREADCRUMBS -->
                                    <ul class="breadcrumb">
                                        <li>
                                            <i class="fa fa-home"></i>
                                            <a href="index.html">首页</a>
                                        </li>
                                        <li>
                                            <a href="#">CMS管理</a>
                                        </li>
                                        <li>首页定时更新</li>
                                    </ul>
                                    <!-- /BREADCRUMBS -->

                                </div>
                            </div>
                        </div>
                        <!-- /PAGE HEADER -->
                        <div class="row">
                            <div class="col-md-12">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="box border primary">
                                            <div class="box-title">
                                                <h4 style="display:block;">
                                                    <i class="fa fa-table"></i>
                                                    上新模板列表
                                                </h4>
                                            </div>
                                            <div class="box-body">
                                                <div class="row">
                                                    <div class="col-md-12">
                                                        <table id="db_brand_list" cellpadding="0" cellspacing="0"
                                                            border="0" class="datatable table table-striped table-bordered table-hover">
                                                        </table>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- /CONTENT-->
                </div>
            </div>
        </div>
    </section>
    <!--/PAGE -->
    <!-- JAVASCRIPTS -->
    <!-- Placed at the end of the document so the pages load faster -->
    <!-- JQUERY -->
    <script src="../../js/jquery/jquery-2.0.3.min.js"></script>
    <!-- spinner -->
    <script src="../../js/spinner/spin.js"></script>
    <!-- BOOTSTRAP -->
    <script src="../../bootstrap-dist/js/bootstrap.min.js"></script>
    <!-- BLOCK UI -->
    <script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>

    <!-- AUTOSIZE -->
    <script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
    <!-- DATA TABLES -->
    <script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
    <script type="text/javascript" src="../../js/datatables/datatable.js"></script>
    <script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
    <script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
    <script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>
    <script type="text/javascript" src="../../js/datepicker/datepicker.js"></script>
    <!-- SELECT2 -->
    <script type="text/javascript" src="../../js/select2/select2.min.js"></script>
    <!-- UNIFORM -->
    <script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
    <!-- COOKIE -->
    <script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
    <script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
    <!-- CUSTOM SCRIPT -->
    <script src="../../js/script.js"></script>
    <script src="../../js/common.js"></script>
    <script language="javascript" type="text/javascript" src="../../js/My97DatePicker/WdatePicker.js"></script>
    <script>
        $(function () {
            var $supplierDataTable = null;
            var temId = null;
            var searchDataBySupplier = function () {
                var url = App.getContextPath() + "admin/template/searchMallStartList.do?imgType=NewProduct";
                if ($supplierDataTable) {
                    $supplierDataTable.api().ajax.url(url).load();
                    return;
                }
                var dtSetting = $.dataTableSetting({
                    "ajaxSource": url,
                    "serverSide": true,
                    "bFilter": false, // 去掉搜索框
                    "bLengthChange": true, // 每页显示数量							
                    "sScrollX": "100%",
                    "sScrollXInner": "100%",
                    "iDisplayLength": 25,
                    "bSort": false,
                    "aoColumns": [{
                        "mDataProp": "id",
                        "sTitle": "页面id",
                        "width": "30%"

                    }, {
                        "sTitle": "生效日期",
                        "width": "30%",
                        "render": function (data, type, row) {
                            return row.startTime ? new Date(row.startTime).format(
                                "yyyy-MM-dd hh:mm:ss") : '';
                        }
                    }, {
                        "sTitle": "状态",
                        "width": "10%",
                        "render": function (data, type, row) {
                            return row.status === 'Valid' ? '正常状态' : '禁用状态'
                        }
                    }, {
                        "sTitle": "操作",
                        "render": function (data, type, row) {
                            var str = '';
                            str +=
                                "<a class='btn btn-primary btn-xs btn-width' style='width:60px;margin-left:0px;margin-right:5px;margin-top:2px;' href='newproduct_template.html?id=" +
                                row.id +
                                "&flag=edit'><i class='fa fa-edit'></i> 编辑</a>";
                            // 
                            if (row.status !== 'Delete') {
                                str +=
                                    "<a class='btn btn-danger btn-xs btn-delete btn-width' style='width:60px;margin-left:0px;margin-right:5px;margin-top:2px;' temId='" +
                                    row.id +
                                    "' href='javascript:void(0)'><i class='fa fa-times-circle'></i> 禁用</a>";
                            }
                            // check-circle
                            if (!row.startTime) {
                                str +=
                                    "<a class='btn btn-success btn-xs btn-width btn-start' style='width:60px;margin-left:0px;margin-right:5px;margin-top:2px;' temId='" +
                                    row.id +
                                    "' href='javascript:void(0)'><i class='fa fa-check-circle'></i> 启用</a>";
                            }
                            str +=
                                "<a class='btn btn-info btn-xs btn-width' style='width:60px;margin-left:0px;margin-right:5px;margin-top:2px;' href='new_home.html?id=" +
                                row.id +
                                "&flag=copy'><i class='fa fa-copy'></i> 复制</a>";
                            return str;
                        }
                    }]

                });

                $supplierDataTable = $("#db_brand_list").dataTable(dtSetting);
            };

            function isDate(str) {
                var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
                result = str.match(reg);
                if (result == null) return false;
                var d = new Date(result[1], result[3] - 1, result[4])
                var newStr = d.getFullYear() + result[2] + (d.getMonth() + 1) + result[2] + d.getDate();
                return str == newStr
            }
            var startSave = function () {
                var input = $("input[name=startDate]");
                var startTime = input.val();
                var regex=/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$/;
                if (!regex.test(startTime)) {
                    input.closest(".form-group").addClass("has-error");
                    return false
                }
                if (new Date(startTime).getTime() < new Date().getTime()) {
                    input.closest(".form-group").addClass("has-error");
                    return false
                }
                input.closest(".form-group").removeClass("has-error");
                $.confirm("确认启用该模板吗?", function () {
                    startAjax(startTime)
                });
            };
            var startAjax = function (startTime) {
                $.ajax({
                    type: "GET",
                    url: App.getContextPath() + "admin/template/updateStartTimeAndStatus.do",
                    data: {
                        startTime: startTime,
                        id: temId,
                        status: 'Valid'
                    },
                    async: true,
                    success: function (result) {
                        if (result.type == 'success') {
                            $.alert("启动模板成功!");
                            $("#start-model").modal("hide");
                            setTimeout(function () {
                                searchDataBySupplier()
                            }, 20)
                        } else {
                            $.alert(result.content);
                        }
                    }
                });
            }
            var deleteAjax = function () {
                $.confirm("确认禁用该模板吗?", function () {
                    $.ajax({
                        type: "GET",
                        url: App.getContextPath() +
                            "admin/template/updateStartTimeAndStatus.do",
                        data: {
                            id: temId,
                            status: 'Delete'
                        },
                        async: true,
                        success: function (result) {
                            if (result.type == 'success') {
                                $.alert("禁用模板成功!");
                                setTimeout(function () {
                                    searchDataBySupplier()
                                }, 20)
                            } else {
                                $.alert(result.content);
                            }
                        }
                    });
                });
            }
            searchDataBySupplier()
            // jeDate({
            //     dateCell:"#startDate",
            //     format:"YYYY-MM-DD hh:mm:ss",
            //     isinitVal:true,
            //     isTime:true, //isClear:false,
            //     minDate:"2014-09-19 00:00:00",
            //     okfun:function(val){}
            // })
            $('body').on('click', '.btn-start', function () {
                temId = $(this).attr('temid');
                $("input[name=startDate]").closest(".form-group").removeClass("has-error");
                $("[name=startDate]").val(new Date().format("yyyy-MM-dd hh:mm:ss"));
                $('#start-model').modal("show");
            })
            $('body').on('click', '.btn-delete', function () {
                temId = $(this).attr('temid');
                deleteAjax()
            })
            $('body').on('click', '.start-save', function () {
                startSave()
            })
            $("#header").load("../head.html");
            App.init();
        })
    </script>
    <!-- /JAVASCRIPTS -->
</body>

</html>